

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>nrgpy.quality.quality &mdash; nrgpy 0.10.19 documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> nrgpy
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">nrgpy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>nrgpy.quality.quality</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for nrgpy.quality.quality</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>


<div class="viewcode-block" id="check_intervals"><a class="viewcode-back" href="../../../nrgpy.quality.html#nrgpy.quality.quality.check_intervals">[docs]</a><span class="k">def</span> <span class="nf">check_intervals</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">return_info</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">show_all_missing_timestamps</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">interval</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;checks for missing intervals in a pandas dataframe with a &quot;Timestamp&quot; column</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    df : object</span>
<span class="sd">        the dataframe to be checked</span>
<span class="sd">    interval : int</span>
<span class="sd">         [deprecated] the averaging interval in seconds</span>
<span class="sd">    verbose : bool</span>
<span class="sd">        print results to terminal; False to skip</span>
<span class="sd">    return_info : bool</span>
<span class="sd">        set to True to return dict with below values</span>
<span class="sd">    show_all_missing_timestamps : bool</span>
<span class="sd">        set to True to show all missing timestamps in verbose option. otherwise, shows first and last 3.</span>

<span class="sd">    Returns</span>
<span class="sd">    ----------</span>
<span class="sd">    dict</span>
<span class="sd">        actual_rows : int</span>
<span class="sd">            actual number of rows in data section of</span>
<span class="sd">            export file (1 subtracted for column headers)</span>
<span class="sd">        expected_rows : int</span>
<span class="sd">            expected number of rows (assumes 10 min. AVG),</span>
<span class="sd">            converts result to whole integer</span>
<span class="sd">        time_range : str</span>
<span class="sd">            range of time represented in export file</span>
<span class="sd">        first_interval : str</span>
<span class="sd">            file starting timestamp</span>
<span class="sd">        last_interval : str</span>
<span class="sd">            file ending timestamp</span>
<span class="sd">        missing_timestamps : list</span>
<span class="sd">            a list of missing timestamps</span>

<span class="sd">    Examples</span>
<span class="sd">    ----------</span>
<span class="sd">    ex. pass a reader.data dataframe for an interval check:</span>

<span class="sd">    &gt;&gt;&gt;  reader = nrgpy.sympro_txt_read()</span>
<span class="sd">    instance created, no filename specified</span>
<span class="sd">    &gt;&gt;&gt; reader.concat_txt(txt_dir=&quot;C:/data/sympro_data/000110/&quot;)</span>
<span class="sd">    ...</span>
<span class="sd">    &gt;&gt;&gt; nrgpy.check_intervals(reader.data, interval=600)</span>
<span class="sd">    Starting timestamp        : 2019-01-01 00:00:00</span>
<span class="sd">    Ending timestamp          : 2019-07-01 04:50:00</span>
<span class="sd">    Data set Duration         : 181 days, 4:50:00</span>
<span class="sd">    Expected rows in data set : 26093</span>
<span class="sd">    Actual rows in data set   : 26093</span>
<span class="sd">    Data set complete.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="s2">&quot;horz&quot;</span> <span class="ow">in</span> <span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">df</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">datetime</span><span class="p">):</span>
        <span class="n">df2</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="c1">#  df2.Timestamp = df2.Timestamp.apply(lambda x: x.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;))</span>
        <span class="n">df2</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="n">_df</span> <span class="o">=</span> <span class="n">df2</span>
        <span class="n">first_interval</span> <span class="o">=</span> <span class="n">_df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">()</span>
        <span class="n">last_interval</span> <span class="o">=</span> <span class="n">_df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">_df</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">time_fmt</span> <span class="o">=</span> <span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M:%S&quot;</span>
        <span class="n">first_interval</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">_df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">min</span><span class="p">(),</span> <span class="n">time_fmt</span><span class="p">)</span>
        <span class="n">last_interval</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">_df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">max</span><span class="p">(),</span> <span class="n">time_fmt</span><span class="p">)</span>

    <span class="n">interval</span> <span class="o">=</span> <span class="n">select_interval_length</span><span class="p">(</span><span class="n">_df</span><span class="p">)</span>
    <span class="n">time_range</span> <span class="o">=</span> <span class="n">last_interval</span> <span class="o">-</span> <span class="n">first_interval</span>
    <span class="n">expected_rows</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">time_range</span><span class="o">.</span><span class="n">total_seconds</span><span class="p">()</span> <span class="o">/</span> <span class="n">interval</span><span class="p">)</span>
    <span class="n">actual_rows</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">df</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
    <span class="n">loss_pct</span> <span class="o">=</span> <span class="nb">round</span><span class="p">(</span>
        <span class="mi">100</span> <span class="o">*</span> <span class="p">(</span><span class="n">expected_rows</span> <span class="o">-</span> <span class="n">actual_rows</span><span class="p">)</span> <span class="o">/</span> <span class="n">expected_rows</span>
    <span class="p">)</span>

    <span class="k">if</span> <span class="n">expected_rows</span> <span class="o">!=</span> <span class="n">actual_rows</span><span class="p">:</span>
        <span class="n">missing_timestamps</span><span class="p">,</span> <span class="n">_df</span> <span class="o">=</span> <span class="n">find_missing_intervals</span><span class="p">(</span><span class="n">_df</span><span class="p">,</span> <span class="n">interval</span><span class="p">)</span>


    <span class="k">if</span> <span class="n">verbose</span> <span class="o">==</span> <span class="kc">True</span><span class="p">:</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Statistical interval      : </span><span class="si">{0}</span><span class="s1"> seconds&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">interval</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Starting timestamp        : </span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">first_interval</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Ending timestamp          : </span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">last_interval</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Data set Duration         : </span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time_range</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Expected rows in data set : </span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">expected_rows</span><span class="p">))</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Actual rows in data set   : </span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">actual_rows</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">expected_rows</span> <span class="o">==</span> <span class="n">actual_rows</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">Data set complete.&#39;</span><span class="p">)</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Interval loss percentage  : </span><span class="si">{0}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">loss_pct</span><span class="p">))</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">Missing </span><span class="si">{0}</span><span class="s1"> timestamps:&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">missing_timestamps</span><span class="p">)))</span>

            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">missing_timestamps</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="mi">8</span> <span class="ow">or</span> <span class="n">show_all_missing_timestamps</span> <span class="o">==</span> <span class="kc">True</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">timestamp</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">missing_timestamps</span><span class="p">):</span>
                    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\t</span><span class="si">{0}</span><span class="se">\t</span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">,</span><span class="n">timestamp</span><span class="p">))</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="k">for</span> <span class="n">timestamp</span> <span class="ow">in</span> <span class="n">missing_timestamps</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;...&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">missing_timestamps</span><span class="p">[</span><span class="o">-</span><span class="mi">3</span><span class="p">:]:</span>
                    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\t</span><span class="si">{0}</span><span class="se">\t</span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span><span class="n">timestamp</span><span class="p">))</span>


    <span class="k">if</span> <span class="n">return_info</span> <span class="o">==</span> <span class="kc">True</span><span class="p">:</span>

        <span class="n">interval_info</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;actual_rows&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">actual_rows</span>
        <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;expected_rows&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">expected_rows</span>
        <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;first_interval&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">first_interval</span>
        <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;last_interval&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">last_interval</span>
        <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;time_range&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">time_range</span>
        <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;loss_pct&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">loss_pct</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;missing_timestamps&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">missing_timestamps</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="n">interval_info</span><span class="p">[</span><span class="s1">&#39;missing_timestamps&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">return</span> <span class="n">interval_info</span></div>


<div class="viewcode-block" id="find_missing_intervals"><a class="viewcode-back" href="../../../nrgpy.quality.html#nrgpy.quality.quality.find_missing_intervals">[docs]</a><span class="k">def</span> <span class="nf">find_missing_intervals</span><span class="p">(</span><span class="n">__df</span><span class="p">,</span> <span class="n">interval</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;find gaps in data dataframe</span>

<span class="sd">    returns</span>
<span class="sd">    ----------</span>
<span class="sd">    list</span>
<span class="sd">        a list of all missing intervals</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_df</span> <span class="o">=</span> <span class="n">__df</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
    <span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>

    <span class="n">_df</span><span class="p">[</span><span class="s1">&#39;data&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
    <span class="n">_df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">to_datetime</span><span class="p">(</span><span class="n">_df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">])</span>
    <span class="n">_df</span><span class="o">.</span><span class="n">set_index</span><span class="p">(</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
    <span class="n">_df</span> <span class="o">=</span> <span class="n">_df</span><span class="o">.</span><span class="n">reindex</span><span class="p">(</span><span class="n">pd</span><span class="o">.</span><span class="n">date_range</span><span class="p">(</span><span class="n">start</span><span class="o">=</span><span class="n">_df</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">end</span><span class="o">=</span><span class="n">_df</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">freq</span><span class="o">=</span><span class="s1">&#39;</span><span class="si">{0}</span><span class="s1">s&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">interval</span><span class="p">)))</span>

    <span class="n">missing_timestamps</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">_df</span><span class="o">.</span><span class="n">iterrows</span><span class="p">():</span>

        <span class="k">if</span> <span class="n">row</span><span class="p">[</span><span class="s1">&#39;data&#39;</span><span class="p">]</span> <span class="o">!=</span> <span class="kc">True</span><span class="p">:</span>
            <span class="n">missing_timestamps</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">index</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">missing_timestamps</span><span class="p">,</span> <span class="n">_df</span></div>


<div class="viewcode-block" id="select_interval_length"><a class="viewcode-back" href="../../../nrgpy.quality.html#nrgpy.quality.quality.select_interval_length">[docs]</a><span class="k">def</span> <span class="nf">select_interval_length</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">seconds</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;returns the mode of the first 10 intervals of the data set</span>

<span class="sd">    parameters</span>
<span class="sd">    ----------</span>
<span class="sd">        reader : nrgpy reader object</span>
<span class="sd">        seconds : bool</span>
<span class="sd">            (True) set to False to get interval length in minutes</span>

<span class="sd">    returns</span>
<span class="sd">    -------</span>
<span class="sd">        int</span>

<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>

    <span class="n">formatter</span> <span class="o">=</span> <span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M:%S&quot;</span>
    <span class="n">interval</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">interval</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="nb">int</span><span class="p">(</span>
                    <span class="p">(</span><span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">],</span> <span class="n">formatter</span><span class="p">)</span> <span class="o">-</span> <span class="n">datetime</span><span class="o">.</span><span class="n">strptime</span><span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">loc</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="n">formatter</span><span class="p">)</span>
                    <span class="p">)</span><span class="o">.</span><span class="n">seconds</span><span class="p">)</span>
                <span class="p">)</span>

        <span class="k">except</span><span class="p">:</span>
            <span class="n">formatter</span> <span class="o">=</span> <span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M:%S.</span><span class="si">%f</span><span class="s2">&quot;</span>
            <span class="n">interval</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                <span class="nb">int</span><span class="p">(</span>
                    <span class="p">(</span><span class="n">df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">][</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">df</span><span class="p">[</span><span class="s1">&#39;Timestamp&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">])</span><span class="o">.</span><span class="n">seconds</span><span class="p">)</span>
                <span class="p">)</span>

        <span class="c1"># except:</span>
        <span class="c1">#    pass</span>

    <span class="n">interval_s</span> <span class="o">=</span> <span class="n">select_mode_from_list</span><span class="p">(</span><span class="n">interval</span><span class="p">)</span>
    <span class="n">interval_m</span> <span class="o">=</span> <span class="n">interval_s</span><span class="o">/</span><span class="mi">60</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">seconds</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">select_mode_from_list</span><span class="p">(</span><span class="n">interval</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">select_mode_from_list</span><span class="p">(</span><span class="n">interval</span><span class="p">)</span><span class="o">/</span><span class="mi">60</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="k">return</span> <span class="kc">False</span></div>


<div class="viewcode-block" id="select_mode_from_list"><a class="viewcode-back" href="../../../nrgpy.quality.html#nrgpy.quality.quality.select_mode_from_list">[docs]</a><span class="k">def</span> <span class="nf">select_mode_from_list</span><span class="p">(</span><span class="n">lst</span><span class="p">):</span>
    <span class="k">return</span> <span class="nb">max</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">lst</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="n">lst</span><span class="o">.</span><span class="n">count</span><span class="p">)</span></div>


<div class="viewcode-block" id="check_for_missing_txt_files"><a class="viewcode-back" href="../../../nrgpy.quality.html#nrgpy.quality.quality.check_for_missing_txt_files">[docs]</a><span class="k">def</span> <span class="nf">check_for_missing_txt_files</span><span class="p">(</span><span class="n">txt_file_names</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot; check list of files for missing file numbers</span>

<span class="sd">    parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    txt_file_names : list</span>
<span class="sd">        list of SymphoniePRO text file exports</span>

<span class="sd">    returns</span>
<span class="sd">    -------</span>
<span class="sd">    list</span>
<span class="sd">        &quot;missing&quot; text file numbers</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">missing_file_numbers</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">f</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">txt_file_names</span><span class="p">)):</span>

        <span class="n">file_number</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;_&quot;</span><span class="p">)[</span><span class="o">-</span><span class="mi">2</span><span class="p">])</span>

        <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">file_number</span> <span class="o">-</span> <span class="n">_file_number</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
                <span class="n">missing_file_numbers</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>

        <span class="n">_file_number</span> <span class="o">=</span> <span class="n">file_number</span>

    <span class="k">return</span> <span class="n">missing_file_numbers</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2020, NRG Systems, Technical Services.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>